package com.kyxx.mycommonproject.wodedingdan;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.kyxx.mycommonproject.R;
import com.kyxx.mycommonproject.base.LazyFragment;
import com.kyxx.mycommonproject.widget.GridViewForScrollView;
import com.kyxx.mycommonproject.widget.ListViewForScrollView;

public class GoodClassFragment extends LazyFragment {
    // 标志位，标志已经初始化完成。
    private boolean isPrepared;
    private TextView tv;
    private String key;
    private ListView lv_class;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_good_class, container, false);
        tv = (TextView) view.findViewById(R.id.tv);
        lv_class = (ListView) view.findViewById(R.id.lv_class);
        isPrepared = true;
        lazyLoad();
        return view;
    }

    @Override
    protected void lazyLoad() {
        if (!isPrepared || !isVisible) {
            return;
        }
        tv.setText(key);
        GoodClassAdapter goodClassAdapter = new GoodClassAdapter();
        lv_class.setAdapter(goodClassAdapter);
    }

    public void setKey(String key) {
        this.key = key;
    }

    private class GoodClassAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder holder;
            if (view == null) {
                holder = new ViewHolder();
                view = View.inflate(getActivity(), R.layout.item_good_class, null);
                holder.gvfs = (GridViewForScrollView) view.findViewById(R.id.gvfs);
                view.setTag(holder);
            } else {
                holder = (ViewHolder) view.getTag();
            }
            OrderGoodAdapter orderGoodAdapter = new OrderGoodAdapter();
            holder.gvfs.setAdapter(orderGoodAdapter);
            return view;
        }
    }

    public class ViewHolder {
        GridViewForScrollView gvfs;
    }

    private class OrderGoodAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return 5;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolderGood holder;
            if (view == null) {
                holder = new ViewHolderGood();
                view = View.inflate(getActivity(), R.layout.item_good_class_good, null);
                holder.iv_good = (ImageView) view.findViewById(R.id.iv_good);
                holder.tv_good = (TextView) view.findViewById(R.id.tv_good);
                view.setTag(holder);
            } else {
                holder = (ViewHolderGood) view.getTag();
            }
            return view;
        }
    }

    public class ViewHolderGood {
        ImageView iv_good;
        TextView tv_good;
    }
}
